package com.joseph.websocket.client;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.SocketChannel;

public class WSClient extends WebSocketClient {

    public WSClient(URI serverUri) {
        super(serverUri);
    }

    public static void main(String[] args) throws Exception {
//        URI websocketURI = null;
//        try {
//            websocketURI = new URI("wss://api.huobiasia.vip/ws");
//        } catch (URISyntaxException e) {
//            e.printStackTrace();
//        }
//        WSClient client = new WSClient(websocketURI);
//        client.setConnectionLostTimeout(3600);
//        client.connect();
//        client.send("{\"req\":\"market.symbols\"}");
//        client.send("{\"sub\":\"market.overviewv2\"}");
////        while (true) {
////            Thread.sleep(1000);
////            client.sendPing();
////        }
        System.out.println(new String("aa").hashCode());
    }

    public void onOpen(ServerHandshake serverHandshake) {
        System.out.println("client: " + serverHandshake.getHttpStatus());
    }

    @Override
    public void onMessage(String s) {
        System.out.println("client收到消息：" + s);
    }

    public void onClose(int i, String s, boolean b) {
        System.out.println(i + "-" + s + "-" + b);
    }

    public void onError(Exception e) {
        e.printStackTrace();
    }

}
